from deslab import *

a,b,c,d,e,s,sf = syms('a b c d e s f')

# example algorithm 1
X = range(1,7)
S = [a,b,c,d,e,sf]
Sobs=[a,b,c,d,e]
T = [(1,c,1),(1,sf,2),(1,d,5),(2,d,3),(2,e,4),(3,b,4),(3,a,6),(4,d,4),(4,c,3),(5,b,5),(6,b,3)]
X0 = [1]
Xm = []
# constructor of automaton $G_1$    
G = fsa(X,S,T,X0,Xm,Sigobs=Sobs,name='G')
A = labelfailaut(sf)
Gd=diagnoser(G, sf, Sobs)
Gd = Gd.setpar(name='Gd-example1')
save(Gd,'Gd_example1')



# example algorithm 3


a,b,c,d,s,sf = syms('a b c d s f')
X = range(1,12)
S = [a,b,c,d,s,sf]
Sobs=[a,b,c,d]
T = [(1,a,2),(1,b,3),(2,d,4),(2,sf,5),(2,c,6),(3,s,2),(4,b,4),(5,c,8),(5,d,7),
     (6,s,9),(7,a,11),(7,c,10),(8,a,8),(9,c,9),(10,b,10),(10,c,10),(11,c,11)]
table=[(sf, f)]
X0 = [1]
Xm = []
# constructor of automaton $G_1$    
G = fsa(X,S,T,X0,Xm,Sigobs=Sobs,table=table,name='G')
Gd = diagnoser(G, sf, Sobs)
Gd = Gd.setpar(name='Gd-example3')
save(G,'G_example3')
save(Gd,'Gd_example3')


# Example 6 

syms('a b c d e g s f')
X = range(1,12)
S = [a,b,c,d,e,g,s,f]
Sobs=[a,b,c,d,e,g]
T = [(1,c,2),(1,d,6),(1,s,8),(2,f,3),(3,b,4),(3,a,5),(4,e,4),(5,d,5),(6,b,7),(7,d,7),
     (8,g,9),(9,b,10),(10,f,11),(11,d,11)]
X0 = [1]
Xm = []
G6 = fsa(X,S,T,X0,Xm,Sigobs=Sobs,name='G-example-6')

Gd = diagnoser(G6, f, Sobs)
A = labelfailaut(sf)
Gd = Gd.setpar(name='Gd-example-6')
save(G6,'G_example6')
save(Gd,'Gd_example6')


# Example tesis

a,b,c,d,sf,g,x0,x1,x2,x3,x4,x5,x6,x7 = syms('a b c d  f g 0 1 2 3 4 5 6 7')
sigma= [a,b,c,d,sf]
X=[x1,x2,x3,x4,x5,x6,x7]
X0, Xm = [x1], []

transicoes=[[x1,c,x2],[x1,a,x5],[x2,sf,x3],[x3,c,x4],[x4,a,x1],[x6,a,x1],[x6,c,x3],[x7,b,x1],
            [x4,d,x4],[x1,a,x5],[x5,b,x6],[x6,d,x6],[x7,d,x7],[x3,a,x7]]
sigmaobs = [a,b,c]
G7= fsa(X,sigma,transicoes,X0,Xm,Sigobs=sigmaobs,name='$G$') 
Gd7 = diagnoser(G,sf,sigmaobs)

save(G7,'G_example7')
save(Gd7,'Gd_example7')

#
syms('a b c d g t f ')
X=range(1,13)
S=[a,b,d,e,g,t,f]
So=[a,b,d,e,g,t]
Xm=[]
X0=[1]
T=[(1,f,2),(2,a,3),(3,b,4),(4,g,5),(5,t,6),(6,t,6),(1,a,7),(7,b,11),(11,g,12),
   (12,d,7),(7,f,8),(8,b,9),(9,g,10),(10,d,3)]
G8= fsa(X,S,T,X0,Xm,Sigobs=So,name='$G$') 
draw(G8)
D8=diagnoser(G8,f,So)
Gl=G8//A
Gt=D8//Gl
Gt.style='rectangle'
draw(D8,Gd7)


